import { ITab } from '../type/Index'
export type TabsState = {
  tabsList: Array<ITab>
}

export const state: TabsState = {
  tabsList: []
}

export const mutations = {
  addTabs: (state: TabsState, val: ITab) => {
    // 判断如果已存在就不存，如果不存在就放进去
    // console.log(val);
    if (state.tabsList.some(item => item.path === val.path)) {
      return
    }
    state.tabsList.push(val)
  },
  saveTabs: (state: TabsState, val:Array<ITab>) => {
    state.tabsList = val
  }
}

export const actions = {}

export const getters = {
  //获取tabs
  getTabsList: (state: TabsState) => {
    return state.tabsList
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
